
package de.dtools.n2g.core;

/**
 *	@project:	note2go
 *	@author:	D.Toepel
 *	@version:	2009-08-06
 *	@note:		---
 *	
 *	Copyright (C) 2009  D.Toepel <de.dtools> {at} <gmail> {dot} <com>
 *	
 *	This program is free software: you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License as published by
 *	the Free Software Foundation, either version 3 of the License, or
 *	(at your option) any later version.
 *	
 *	This program is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *	
 *	You should have received a copy of the GNU General Public License
 *	along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *	
 */
import java.util.Vector;

import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.MutableTreeNode;

public class Label extends DefaultMutableTreeNode implements MutableTreeNode {
	
	private static final long serialVersionUID = 1L;
	
	Label label;
    Vector<Label> subLabels;
    private String name;
    private Integer labelID;
	private String toolTip;
	private Boolean isNote = false;
	private Boolean isNewNote = false;

    public Label(String name, Integer labelID) {
        this.name = name;
        this.labelID = labelID;
        label = null;
        subLabels = new Vector<Label>();
    }

    public static void linkAllLabels(Label l, Label[] sl) {
        for (Label sub : sl) {
        	Label temp = new Label(sub.getName(), sub.getLabelID());
        	l.subLabels.add(temp);
        	temp.label = l;
        }
    }

    public static void linkLabels(Label l, Label[] sl) {
        for (Label sub : sl) {
        	l.subLabels.add(sub);
        	sub.label = l;
        }
    }
    
    public static void linkLabelResult(Label[] nodes, Label[] leafs){
    	for (int i = 1; i < nodes.length; i++) {
    		linkLabels(nodes[i-1],new Label[]{nodes[i]});
		}
    	linkAllLabels(nodes[nodes.length - 1], leafs);
    }
    
    public void setName(String name){
    	this.name = name;
    }
    public void setToolTip(String toolTip){
    	this.toolTip = toolTip;
    }
    
    public void isNote(Boolean isNote){
    	this.isNote = isNote; 
    }
    
    public void isNewNote(Boolean isNewNote){
    	this.isNewNote = isNewNote; 
    }
    
    public void setLabelID(Integer labelID){
    	this.labelID = labelID;
    }
    
   
    
    
/// getter methods ///////////////////////////////////

    public String toString() { return name; }
    public String getName() { return name; }
    public Integer getLabelID() { return labelID; }
    public Label getLabel() { return label; }
    public int getChildCount() { return subLabels.size(); }
    public String getToolTip(){ return this.toolTip; }
    public Boolean isNote(){ return isNote; }
    public Boolean isNewNote(){ return isNewNote; }
    public Label getChildAt(int i) {
        return (Label)subLabels.elementAt(i);
    }
    public int getIndexOfChild(Label sub) {
        return subLabels.indexOf(sub);
    }
    


}
